package quq.missq.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import java.util.ArrayList;
import quq.missq.Constants;
import quq.missq.R;
import quq.missq.activity.TaPageActivity;
import quq.missq.beans.GoddessBean;
import quq.missq.utils.ImageLoadUtil;
import quq.missq.utils.UIHelper;
import quq.missq.views.PagerAdapter;

/**
 * Created by River on 9/6/15.
 */
public class GoddessPagerAdapter extends PagerAdapter{

    private int height,width = 0;
    private Context mContext;
    private ArrayList<GoddessBean.Goddess> mGoddesses;

    public GoddessPagerAdapter(Context pContext){
        this.mContext = pContext;
        //height = UIHelper.getScreenHeight(mContext)-70;
       // width = UIHelper.getScreenWidth(mContext)-50;
    }

    public void setData(ArrayList<GoddessBean.Goddess> goddesses){
        this.mGoddesses = goddesses;
    }

    @Override
    public int getCount() {
        return mGoddesses.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        ImageView iv = new ImageView(container.getContext());
        iv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT));
        iv.setImageResource(R.mipmap.default_empty2);
        ImageLoadUtil.loadImage(iv, Constants.IMAGE_HOST + mGoddesses.get(position).getCover().getPreview(), R.mipmap.default_empty2);
        //iv.setScaleType(ImageView.ScaleType.FIT_XY);
        container.addView(iv);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(mContext, TaPageActivity.class);
                intent.putExtra("uid",mGoddesses.get(position).getUser().getId());
                intent.putExtra("username",mGoddesses.get(position).getUser().getNkname());
                mContext.startActivity(intent);
            }
        });
        return iv;
    }

}
